Skip to content

Chore/move more types to ir#152706

Draft
Jamesbarford wants to merge 1 commit intorust-lang:mainfrom
Jamesbarford:chore/move-more-types-to-ir
Draft

Chore/move more types to ir#152706
Jamesbarford wants to merge 1 commit intorust-lang:mainfrom
Jamesbarford:chore/move-more-types-to-ir

Conversation

@Jamesbarford
Copy link
Contributor

r? ghost

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Feb 16, 2026
@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from 3ef4cf0 to c64839d Compare February 16, 2026 12:35
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr self-assigned this Feb 16, 2026
where
F: FnOnce(&mut Self) -> R;
pub trait TyEncoder<'tcx>: ir_codec::TyEncoder<'tcx, Interner = TyCtxt<'tcx>> {}
impl<'tcx, T> TyEncoder<'tcx> for T where T: ir_codec::TyEncoder<'tcx, Interner = TyCtxt<'tcx>> {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this trait have to be moved? This is surprising to me

Might be good to write in the PR description what you're moving and why.

As in, sth like

  • moving Ty
  • also uses other types X which now need to be moved
  • has function which relies on tcx, add method fn XXX to trait Interner

feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

#[rustc_diagnostic_item = "Ty"]
#[rustc_pass_by_value]
#[rustc_has_incoherent_inherent_impls]
pub struct Ty<I: Interner>(pub I::Interned<WithCachedTypeInfo<TyKind<I>>>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be in a mod ty or mod sty to mirror rustc_middle

#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[rustc_diagnostic_item = "Ty"]
#[rustc_pass_by_value]
#[rustc_has_incoherent_inherent_impls]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dubious :3 i guess that's a way to simply the migration. Removing this before merge/add a TODO rn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was experimenting with things. This in my opinion is 'cheating', I'll remove it

#[inline]
pub fn interned(self) -> I::Interned<WithCachedTypeInfo<TyKind<I>>> {
self.0
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?

}

#[inline]
#[allow(rustc::pass_by_value)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why by ref?


impl<I: Interner> TypeSuperVisitable<I> for Ty<I>
where
I::Interned<WithCachedTypeInfo<TyKind<I>>>: Deref<Target = WithCachedTypeInfo<TyKind<I>>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be item bound of I::Interned, same with all other where-bounds here

I::Region: TypeFoldable<I> + TypeVisitable<I>,
I::Term: From<Ty<I>>,
I::Tys: TypeFoldable<I> + TypeVisitable<I>,
I::Interned<WithCachedTypeInfo<TyKind<I>>>:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all item bounds of Interned

/// This offset is also chosen so that the first byte is never < 0x80.
pub const SHORTHAND_OFFSET: usize = 0x80;

pub trait TyEncoder<'tcx>: SpanEncoder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels rustc specific and is not used by r-a afaik, so I'd prefer keeping this in rustc_middle for now

}

pub trait Interned<T>: Clone + Copy + Hash + PartialEq + Eq + Debug {
fn new_unchecked(t: &T) -> Self;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 where is that used, surprising that we'd ever want to use this in rustc_next_trait_solver

+ Hash
+ Eq
+ PartialEq
+ Deref<Target = T>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a super trait bounds of a single Interned trait

#![cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir")]
// tidy-alphabetical-start
#![allow(rustc::direct_use_of_rustc_type_ir)]
#![allow(rustc::pass_by_value)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes to rustc_next_trait_solver look as expected

don't need to change rust-analyzer for now as they don't directly depend on rustc. We need ot change it to test that it's correct, but I'd wait on actually getting rustc to work for this

View changes since this review

@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from c64839d to 9b563d7 Compare February 26, 2026 09:28
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

BlobDecoder, BytePos, ByteSymbol, DUMMY_SP, Pos, RemapPathScopeComponents, SpanData,
SpanDecoder, Symbol, SyntaxContext, kw,
};
use rustc_type_ir::codec::TyDecoder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TyDecoder should stay in rustc_middle 🤔

def_id: DefId,
args: Self::GenericArgs,
) -> Ty<'tcx> {
Ty::new_coroutine_witness_for_coroutine(self, def_id, args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why method on Interner insetead of Ty?

}

fn ty_discriminant_ty(self, ty: Ty<'tcx>) -> Ty<'tcx> {
ty.discriminant_ty(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment on lines +746 to +748
fn u8_type(self) -> Ty<'tcx> {
self.types.u8
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you, potentially in an earlier PR so that we can test it for perf, stop using self.types.X and instead use Ty::new_uint(..). This should inline to the same thing and means whether we have a precomputed interned type for u8 is not handled by the interner

use rustc_macros::{Lift, extension};
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_span::{Ident, RemapPathScopeComponents, Symbol, kw, sym};
use rustc_type_ir::inherent::{GenericArgs as _, IntoKind as _};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? we should never import these traits 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is due to have implemented IntoKind on Ty to expose the kind() method but then not made a pub fn kind(&self) pass-through method that previously existed. I would think once I've implemented the pass-through I can remove this. As for GenericArgs, it could possibly a similar reason

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that with Ty you now have an inherent fn kind method 🤔

tcx,
trait_def_id,
[self_ty, Ty::new_tup(tcx, args)],
[self_ty, ty::Ty::new_tup(tcx, args)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should lint 🤔 as we want people to consistently use Ty and import it from rustc_middle::ty. We should have some #[cfg_if("nightly", rustc_diagnostic_item = "Ty")] attribute on Ty

write!(p, ")")?;

if !sig.output().is_unit() {
if !matches!(sig.output().kind(), ty::Tuple(tys) if tys.is_empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:<

type GenericArgsSlice: Copy + Debug + Hash + Eq + SliceLike<Item = Self::GenericArg>;
type GenericArg: GenericArg<Self>;
type Term: Term<Self>;
type Term: Term<Self> + From<Ty<Self>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From<Ty<Self>> should be super-trait of Term instead

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Mar 2, 2026
@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from 4bb23fa to f89feb9 Compare March 2, 2026 16:24
@rust-log-analyzer

This comment has been minimized.

@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from f89feb9 to 0780eb0 Compare March 3, 2026 10:13
@rust-log-analyzer

This comment has been minimized.

@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from 207dc41 to bc41000 Compare March 3, 2026 10:54
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from bc41000 to cf831bc Compare March 5, 2026 10:17
@Jamesbarford Jamesbarford force-pushed the chore/move-more-types-to-ir branch from cf831bc to 6b77eb6 Compare March 5, 2026 10:30
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-gcc failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           1.6G   12K  1.6G   1% /run/user/1001
================================================================================

Sufficient disk space available (95102848KB >= 52428800KB). Skipping cleanup.
##[group]Run echo "[CI_PR_NUMBER=$num]"
echo "[CI_PR_NUMBER=$num]"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---
   Compiling matchers v0.2.0
error[E0308]: mismatched types
   --> compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs:810:28
    |
810 |                 cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Poll).into()),
    |                    ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `rustc_type_ir::Interner::AdtId`, found `rustc_type_ir::Interner::DefId`
    |                    |
    |                    arguments to this method are incorrect
    |
    = note: expected associated type `<I as Interner>::AdtId`
               found associated type `<I as Interner>::DefId`
    = note: an associated type was expected, but a different one was found
note: method defined here
   --> compiler/rustc_type_ir/src/interner.rs:224:8
    |
224 |     fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef;
    |        ^^^^^^^
help: try removing the method call
    |
810 -                 cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Poll).into()),
810 +                 cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Poll)),
    |

error[E0308]: mismatched types
   --> compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs:813:32
    |
813 |                     cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Option).into()),
    |                        ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `rustc_type_ir::Interner::AdtId`, found `rustc_type_ir::Interner::DefId`
    |                        |
    |                        arguments to this method are incorrect
    |
    = note: expected associated type `<I as Interner>::AdtId`
               found associated type `<I as Interner>::DefId`
    = note: an associated type was expected, but a different one was found
note: method defined here
   --> compiler/rustc_type_ir/src/interner.rs:224:8
    |
224 |     fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef;
    |        ^^^^^^^
help: try removing the method call
    |
813 -                     cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Option).into()),
813 +                     cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Option)),
    |

For more information about this error, try `rustc --explain E0308`.
[RUSTC-TIMING] rustc_next_trait_solver test:false 1.382
error: could not compile `rustc_next_trait_solver` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] matchers test:false 0.085
warning: ignoring -C extra-filename flag due to -o flag

error: associated type in `impl` without body
  --> compiler/rustc_middle/src/ty/context/impl_interner.rs:59:5
   |
59 |     type GenericArgsRef: ty::GenericArgsRef<Self>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
   |                                                  |
   |                                                  help: provide a definition for the type: `= <type>;`

error: bounds on `type`s in `impl`s have no effect
  --> compiler/rustc_middle/src/ty/context/impl_interner.rs:59:26
   |
59 |     type GenericArgsRef: ty::GenericArgsRef<Self>;
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0437]: type `GenericArgsRef` is not a member of trait `Interner`
  --> compiler/rustc_middle/src/ty/context/impl_interner.rs:59:5
   |
59 |     type GenericArgsRef: ty::GenericArgsRef<Self>;
   |     ^^^^^--------------^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |     |    |
   |     |    help: there is an associated type with a similar name: `GenericArgs`
   |     not a member of trait `Interner`

---

error[E0404]: expected trait, found type alias `ty::GenericArgsRef`
   --> compiler/rustc_middle/src/ty/context/impl_interner.rs:59:26
    |
 59 |     type GenericArgsRef: ty::GenericArgsRef<Self>;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^ type aliases cannot be used as traits
    |
help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias
   --> compiler/rustc_middle/src/ty/generic_args.rs:390:1
    |
390 - pub type GenericArgsRef<'tcx> = &'tcx GenericArgs<'tcx>;
390 + pub trait GenericArgsRef<'tcx> = &'tcx GenericArgs<'tcx>;
    |

error[E0425]: cannot find value `coroutine_args` in this scope
   --> compiler/rustc_middle/src/ty/context/impl_interner.rs:931:17
    |
931 |                 coroutine_args[def.index as usize]
    |                 ^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `tcx` in this scope
   --> compiler/rustc_middle/src/ty/context/impl_interner.rs:941:31
    |
941 |         GenericArgs::for_item(tcx, wrapper_def_id, |param, args| match param.kind {
    |                               ^^^ not found in this scope

error[E0433]: failed to resolve: use of undeclared type `GenericParamDefKind`
   --> compiler/rustc_middle/src/ty/context/impl_interner.rs:942:13
    |
942 |             GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(),
    |             ^^^^^^^^^^^^^^^^^^^ use of undeclared type `GenericParamDefKind`
    |
help: consider importing this enum through its public re-export
    |
  3 + use crate::ty::GenericParamDefKind;
    |

error[E0433]: failed to resolve: use of undeclared type `GenericParamDefKind`
   --> compiler/rustc_middle/src/ty/context/impl_interner.rs:942:45
    |
942 |             GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(),
    |                                             ^^^^^^^^^^^^^^^^^^^ use of undeclared type `GenericParamDefKind`
    |
help: consider importing this enum through its public re-export
    |
  3 + use crate::ty::GenericParamDefKind;
    |
---

error[E0425]: cannot find value `tcx` in this scope
   --> compiler/rustc_middle/src/ty/context/impl_interner.rs:948:21
    |
948 |                     tcx.type_of(param.def_id).instantiate(tcx, args).into()
    |                     ^^^ not found in this scope

error[E0425]: cannot find value `tcx` in this scope
   --> compiler/rustc_middle/src/ty/context/impl_interner.rs:948:59
    |
948 |                     tcx.type_of(param.def_id).instantiate(tcx, args).into()
    |                                                           ^^^ not found in this scope

error[E0433]: failed to resolve: use of undeclared type `GenericParamDefKind`
    --> compiler/rustc_middle/src/ty/context/impl_interner.rs:1021:13
     |
1021 |             GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(),
     |             ^^^^^^^^^^^^^^^^^^^ use of undeclared type `GenericParamDefKind`
     |
help: consider importing this enum through its public re-export
     |
   3 + use crate::ty::GenericParamDefKind;
     |

error[E0433]: failed to resolve: use of undeclared type `GenericParamDefKind`
    --> compiler/rustc_middle/src/ty/context/impl_interner.rs:1021:45
     |
1021 |             GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(),
     |                                             ^^^^^^^^^^^^^^^^^^^ use of undeclared type `GenericParamDefKind`
     |
help: consider importing this enum through its public re-export
     |
   3 + use crate::ty::GenericParamDefKind;
     |
---

error[E0425]: cannot find value `tcx` in this scope
    --> compiler/rustc_middle/src/ty/context/impl_interner.rs:1027:60
     |
1027 |                     self.type_of(param.def_id).instantiate(tcx, args).into()
     |                                                            ^^^ not found in this scope

error[E0425]: cannot find value `tcx` in this scope
    --> compiler/rustc_middle/src/ty/context/impl_interner.rs:1036:21
     |
1036 |         Ty::new_adt(tcx, pin, self.mk_args(&[Ty::new_ref(tcx, r, ty, mutbl).into()]))
     |                     ^^^ not found in this scope

error[E0425]: cannot find value `tcx` in this scope
    --> compiler/rustc_middle/src/ty/context/impl_interner.rs:1036:58
     |
1036 |         Ty::new_adt(tcx, pin, self.mk_args(&[Ty::new_ref(tcx, r, ty, mutbl).into()]))
     |                                                          ^^^ not found in this scope

error[E0425]: cannot find value `tcx` in this scope
    --> compiler/rustc_middle/src/ty/context/impl_interner.rs:1043:38
     |
1043 |         let context_ty = Ty::new_adt(tcx, context_adt_ref, context_args);
     |                                      ^^^ not found in this scope

error[E0425]: cannot find value `tcx` in this scope
    --> compiler/rustc_middle/src/ty/context/impl_interner.rs:1044:25
     |
1044 |         Ty::new_mut_ref(tcx, self.lifetimes.re_erased, context_ty)
     |                         ^^^ not found in this scope

Some errors have detailed explanations: E0106, E0404, E0425, E0433, E0437.
For more information about an error, try `rustc --explain E0106`.
[RUSTC-TIMING] rustc_middle test:false 2.582

For more information how to resolve CI failures of this job, visit this link.

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 7, 2026

☔ The latest upstream changes (presumably #153544) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants